import { getCurrentInstance } from 'vue'
import { Form } from 'ant-design-vue'
import type { WrappedFormUtils } from 'ant-design-vue/types/form/form'

// TODO  这一块需要封装好 封装useForm
export const useForm = (options?: any): [WrappedFormUtils, WrappedFormUtils] => {
  const vm = getCurrentInstance()
  if (!vm) throw new Error('must be called in setup')

  // 这里的报红  暂不影响，后续优化 - 不做类型转化会报错
  const form = (Form as any).createForm(vm.proxy, options)
  return [form, form]
}
